package com.example.demo.common;

import java.util.HashMap;
import java.util.Map;

/**
 * excel前台到后台的路由
 * 用于路由  执行的 校验规则 比对参照{@link RoutingKeyEnum}
 *
 * @author Dax
 * @since 19:22  2018/5/17
 */
public final class ExcelImportRouter {


    private ExcelImportRouter() {
    }

    public static ExcelConfig router(String routingKey) {
        ExcelConfig excelConfig = new ExcelConfig();
        //       贫困乡镇 帮扶责任
        if (RoutingKeyEnum.TOWN_HR.value().equals(routingKey)) {
//            对应excel 中的所有字段 即使数据库没有对应的字段也需要指定  顺序必须跟表左右一致
            String[] cols = {"cityName",
                    "cntyName",
                    "townId",
                    "groupName",
                    "mainRspUnit",
                    "mainRspderUnit",
                    "groupJobtt",
                    "expertTeamName",
                    "leadExpertName",
                    "workUnit",
                    "jobtt",
                    "titleDesc"};
//             字段校验规则  不需要校验 不声明即可
            CellRule townIdRule = new CellRule.RuleBuilder().isStr(40).builder();

            CellRule groupNameRule = new CellRule.RuleBuilder().isStr(20).builder();
            CellRule mainRspUnitRule = new CellRule.RuleBuilder().isStr(20).builder();
            CellRule mainRspderUnitRule = new CellRule.RuleBuilder().isStr(20).builder();
            CellRule groupJobttRule = new CellRule.RuleBuilder().isStr(20).builder();

            CellRule expertTeamNameRule = new CellRule.RuleBuilder().isStr(20).builder();
            CellRule leadExpertNameRule = new CellRule.RuleBuilder().isStr(20).builder();
            CellRule workUnitRule = new CellRule.RuleBuilder().isStr(20).builder();
            CellRule jobttRule = new CellRule.RuleBuilder().isStr(20).builder();
            CellRule titleDescRule = new CellRule.RuleBuilder().isStr(20).builder();

            Map<String, CellRule> ruleMap = new HashMap<>();
//             key 为 setColumnNames() 中对应的字段名
            ruleMap.put("townId", townIdRule);
            ruleMap.put("groupName", groupNameRule);
            ruleMap.put("mainRspUnit", mainRspUnitRule);
            ruleMap.put("mainRspderUnit", mainRspderUnitRule);
            ruleMap.put("groupJobtt", groupJobttRule);
            ruleMap.put("expertTeamName", expertTeamNameRule);
            ruleMap.put("leadExpertName", leadExpertNameRule);
            ruleMap.put("workUnit", workUnitRule);
            ruleMap.put("jobtt", jobttRule);
            ruleMap.put("titleDesc", titleDescRule);

//          区域等级编码
            excelConfig.setAddrLvlEnum(AddrLvlEnum.TOWN);
            excelConfig.setRules(ruleMap);
            excelConfig.setColumnNames(cols);
//            excel 数据（非表头）起止行 行号-1
            excelConfig.setRowNum(3);
//          core 层 对应的服务类
            excelConfig.setCoreService("");
//          core 层 对应的方法名
            excelConfig.setCoreMethod("");
        }
        return excelConfig;
    }

}
